package org.pentaho.di.trans.common;

import java.util.Hashtable;
import java.util.Map;

import org.pentaho.di.core.database.Database;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.logging.LoggingObjectInterface;
import org.pentaho.di.trans.step.BaseStepData;
import org.pentaho.di.trans.step.StepDataInterface;


public class TransactionDbObjectPool extends BaseStepData implements StepDataInterface {
		
	private static Map<String, Database> map_db = new Hashtable<String, Database>();
	
	public static void removeInfo(String stepName) {
		map_db.remove(stepName);
	}

	private TransactionDbObjectPool(){}
	
	public static void storeDatabaseInfo(String stepName,Database db) {
		map_db.put(stepName, db);
	}
	
	public static Database createDBFromConn(String stepName,LoggingObjectInterface parentObject){
		Database db =  new Database(parentObject,map_db.get(stepName).getDatabaseMeta());
		db.setConnection(map_db.get(stepName).getConnection());
		return db;
	}
	
	public static DatabaseMeta getDbMeta(String stepName){
		return map_db.get(stepName).getDatabaseMeta();
	}

}
